package biz.console;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class Result<T>{
    int code;
    String msg;
    T data;
    String key;

    public Result() {
        code = 0;
        msg="success";
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }



    public int code() {
        return code;
    }


    public String msg() {
        return msg;
    }

    public Result<T> code(int code){
        this.code = code;
        return this;
    }

    public Result<T> msg(String msg){
        this.msg = msg;
        return this;
    }

    public Result<T> data(T data){
        this.data = data;
        return this;
    }


    public T data() {
        return data;
    }

    public Result copy(){
        Result result = new Result();
        result.code(code).msg(msg);
        return result;
    }

    public static<T> Result<T> wrap(T t){
        Result<T> result = new Result();
        result.code(0).msg("success").data(t);
        return result;
    }


}
